<template>
  <div class="tabbar-item" @click="itemclick">
    <template v-if="!isactived">
      <slot name="img"></slot>
    </template>
    <template v-else>
      <slot name="imga"></slot>
    </template>
    <div :style="activestyle">
      <slot name="title"></slot>
    </div>
  </div>
</template>

<script>
import { computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
export default {
  props: {
    path: String,
    activecolor: {
      type: String,
      default: 'red'
    }
  },
  setup(props) {
    const router = useRouter()
    const route = useRoute()
    const isactived = computed(() => {
      return route.path.includes(props.path)
    })
    const activestyle = computed(() => {
      return isactived.value ? { color: props.activecolor } : {}
    })
    const itemclick = () => {
      router.push(props.path)
    }
    return {
      isactived,
      activestyle,
      itemclick
    }
  }
}
</script>

<style>
.tabbar-item {
  flex: 1;
  text-align: center;
  font-size: 14px;
  cursor: pointer;
}
.tabbar-item img {
  margin-top: 4px;
  margin-bottom: 4px;
  width: 20px;
  height: 20px;
  vertical-align: bottom;
}
.active {
  color: red;
}
</style>
